package com.antdsp.web.dto;

import com.antdsp.data.entity.system.SystemMenu;
import com.antdsp.utils.TreeNodeVO;
import com.antdsp.utils.TreeUtil;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class MyMenuTree extends TreeNodeVO<MyMenuTree> {

    private String name;

    private String path;

    private String icon;

    private String permission;

    private String type;

    private boolean hideInMenu;

    private List<MyMenuTree> children;

    private Integer orderNum;

    public Integer getOrderNum() {
        return orderNum;
    }

    public void setOrderNum(Integer orderNum) {
        this.orderNum = orderNum;
    }

    public String getName() {
        return name;
    }

    public String getPath() {
        return path;
    }

    public String getIcon() {
        return icon;
    }

    public String getPermission() {
        return permission;
    }

    public String getType() {
        return type;
    }

    public List<MyMenuTree> getChildren() {
        return children;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }

    public void setType(String type) {
        this.type = type;
    }

    public void setChildren(List<MyMenuTree> children) {
        this.children = children;
    }

    public void appendChildren(MyMenuTree childMen) {
        if(children == null) {
            children = new ArrayList<>();
        }
        children.add(childMen);
    }

    public boolean isHideInMenu() {
        return hideInMenu;
    }

    public void setHideInMenu(boolean hideInMenu) {
        this.hideInMenu = hideInMenu;
    }

    public static List<MyMenuTree> buildTree(List<SystemMenu> menus, String root) {
        List<MyMenuTree> trees = new ArrayList<>();
        MyMenuTree node = null;
        for (SystemMenu menu : menus) {
            node = new MyMenuTree();
            BeanUtils.copyProperties(menu, node);
            //node.setValue(menu.getId());
            //node.setLabel(menu.getTitle());
            trees.add(node);
        }
        return TreeUtil.build(trees, root) ;
    }
}
